package cn.itsource.zcn.org.controller;

import cn.itsource.zcn.org.domain.Systemdictionarydetail;
import cn.itsource.zcn.org.domain.Systemdictionarytype;
import cn.itsource.zcn.org.query.SystemdictionarydetailQuery;
import cn.itsource.zcn.org.query.SystemdictionarytypeQuery;
import cn.itsource.zcn.org.service.ISystemdictionarydetailService;
import cn.itsource.zcn.utils.AjaxResult;
import cn.itsource.zcn.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (Systemdictionarydetail)表控制层
 *
 * @author makejava
 * @since 2021-08-14 09:12:08
 */
@RestController
@RequestMapping("/dicdetail")
public class SystemdictionarydetailController {
    /**
     * 服务对象
     */
    @Autowired
    private ISystemdictionarydetailService tSystemdictionarydetailService;

    /**
     * 查询全部数据
     *
     * @return List<>
     */
    @GetMapping
    public List<Systemdictionarydetail> queryAll() {
        return tSystemdictionarydetailService.queryAll();
    }
    /**
     * 分页+高级
     *
     * @return QueryResult<Systemdictionarytype>
     */
    @PostMapping
    public QueryResult<Systemdictionarydetail> pageQuery(@RequestBody SystemdictionarydetailQuery SystemdictionarydetailQuery){
        return tSystemdictionarydetailService.queryPage(SystemdictionarydetailQuery);
    }

    /**
     * 编辑或者新增
     *
     * @return AjaxResult
     */
    @PutMapping
    public AjaxResult saveOrUpdate(@RequestBody Systemdictionarydetail Systemdictionarydetail){
        try {
            if(Systemdictionarydetail.getId() == null){
                tSystemdictionarydetailService.save(Systemdictionarydetail);
            }else {
                tSystemdictionarydetailService.update(Systemdictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }
    /**
     * 删除单条
     *
     * @return AjaxResult
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            tSystemdictionarydetailService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }
    /**
     * 批量删除
     *
     * @return AjaxResult
     */
    @PatchMapping
    public AjaxResult deleteBatch(@RequestBody List<Integer> ids){
        try {
            tSystemdictionarydetailService.deleteBatch(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }
}
